package com.douwong.student.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.douwong.student.R;
import com.douwong.student.model.AnswerRecord;
import com.douwong.student.utils.ImagFilterUtil;

import java.util.ArrayList;


/**
 * 答题记录适配器
 * 
 * @author leihuajie
 * 
 */
public class AnswerExhangeAdapter extends BaseAdapter {

	private Context context;
	private int i;
	private ArrayList<AnswerRecord> list;

	public AnswerExhangeAdapter(Context context, int i,
								ArrayList<AnswerRecord> list) {
		this.context = context;
		this.i = i;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;
		if (convertView == null) {
			holder = new Holder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.answer_exchange_item, null);
			holder.answer_type_text = (TextView) convertView
					.findViewById(R.id.answer_type_text);
			holder.file_name_text = (TextView) convertView
					.findViewById(R.id.file_name_text);
			holder.subject_text = (TextView) convertView
					.findViewById(R.id.subject_text);
			holder.create_time_text = (TextView) convertView
					.findViewById(R.id.create_time_text);
			holder.star_count_text = (TextView) convertView
					.findViewById(R.id.star_count_text);
			holder.iv_exchange_star = (ImageView) convertView
					.findViewById(R.id.iv_exchange_star);
			convertView.setTag(holder);
			if (i == 0) {// 问答互动

			} else if (i == 1) {// 手写互动
				holder.answer_type_text.setVisibility(View.GONE);
			}
		} else {
			holder = (Holder) convertView.getTag();
		}
		if (list.size() > 0) {
			String timesStr = list.get(position).getCreateTime()
					.substring(0, 10);
		//	holder.file_name_text.setText(list.get(position).getTitleName());  设置标题
			ImagFilterUtil.filterImage(holder.file_name_text,list.get(position).getTitleName(),1);
			holder.subject_text.setText(list.get(position).getSubject());
			holder.create_time_text.setText(timesStr);
			holder.star_count_text.setText(String.valueOf(list.get(position)
					.getAwardCount()));
			String star = String.valueOf(list.get(position).getAwardCount());
			if (star.equals("0")) {
				holder.iv_exchange_star.setVisibility(View.GONE);
				holder.star_count_text.setText("----");
			}
			if (i == 0) {
				holder.answer_type_text.setText(list.get(position).getType()
						.getTip());
			}
		}
		return convertView;
	}

	class Holder {
		TextView star_count_text, file_name_text, answer_type_text,
				subject_text, create_time_text;
		ImageView iv_exchange_star;
	}
}
